<!DOCTYPE html>
<html>

<head>
  <meta charset="UTF-8" />
  <meta http-equiv="X-UA-Compatible" content="IE=edge" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <title>Document</title>
</head>

<body>
  <div id="app"></div>
  <template id="pengfan">
    <button @click="changeFullName">修改了fullName</button>
    <h2>{{fullName}}</h2>
  </template>
  <script src="../js/vue.js"></script>
  <script>
    Vue.createApp({
      template: "#pengfan",
      data() {
        return {
          firstName: "Kobe",
          lastName: "Bryant",
        };
      },
      computed: {
        //fullName 的 getter 方法
        fullName() {
          return this.firstName + " " + this.lastName;
        },

        //fullName的getter和setter方法
        fullName: {
          get: function () {
            console.log(2222)
            return this.firstName + " " + this.lastName;

          },
          set: function (newValue) {
            console.log(newValue);
            console.log(11111)
            const names = newValue.split(" ");
            this.firstName = names[0];
            this.lastName = names[1];
          },
        },
      },
      methods: {
        changeFullName() {
          this.fullName = "Fan Peng"
        }
      },
    }).mount("#app");
  </script>
</body>

</html>